package model

import (
	"database/sql/driver"
	"encoding/json"
	"time"
)

type Recondings []int //自定义存储打卡记录数组的结构体

type Routine struct {
	Id          int        `gorm:"primary-key;unique;column:id"`        //打卡事项id
	Title       string     `gorm:"not null;column:title"`               //打卡事项名称
	Reconding   Recondings `gorm:"not null;column:reconding;type:json"` //打卡记录
	USERAccount string     `gorm:"not null;column:useraccount"`         //打卡事项所属的用户
	STime       time.Time  `gorm:"not null;column:stime"`               //打卡开始时间
}

func (t *Recondings) Scan(value interface{}) error { //从数据库中取出时将string转为json
	bytesValue, _ := value.([]byte)
	return json.Unmarshal(bytesValue, t)
}

func (t Recondings) Value() (driver.Value, error) { //存入数据库前将数组转为string存入
	return json.Marshal(t)
}
